package lily.phs.healthedu;

import lily.phs.child.ImageList;
import lily.phs.database.Constants;
import lily.phs.epidemic.EpidemicList;
import lily.phs.object.HealthEdu;
import lily.phs.urh.MainActivity;
import lily.phs.urh.PeopleList;
import lily.phs.urh.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class HealthMain extends Activity implements OnClickListener,Constants
{
	private TextView tv;
	private Button bt,rightBtn,rightBtn2;
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.health_button);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.i_title);
		
		tv=(TextView) findViewById(R.id.title);
		tv.setText("健康教育");
		bt=(Button) findViewById(R.id.title_left_btn);
		rightBtn = (Button) findViewById(R.id.title_right_btn);
        rightBtn2 = (Button) findViewById(R.id.title_right_btn2);
        rightBtn.setVisibility(View.GONE);
        rightBtn2.setVisibility(View.GONE);
		bt.setText("后退");
		bt.setOnClickListener(new Button.OnClickListener()
		{

			@Override
			public void onClick(View v) {
				 //TODO Auto-generated method stub
//				Intent intent =new Intent();
//				intent.setClass(HealthMain.this,MainActivity.class);
//				startActivity(intent);
				HealthMain.this.finish();
			}
			
		});

		GridView gv=(GridView) findViewById(R.id.grid);
		final int[] image = { 
				R.drawable.healthedu_1,
				R.drawable.healthedu_2,
				R.drawable.healthedu_3};
		final String[] name={"健康培训","我的资料","教育活动"};
		MyAdapter adapter = new MyAdapter(this, image, name);
		
		gv.setAdapter(adapter);

		gv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Intent in;
				switch (arg2) {
				case 0:
					in=new Intent(HealthMain.this,HealthTrainActivity.class);//转到健康培训去
					startActivity(in);
					overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
					break;
				//case 1:
					//in=new Intent(HealthMain.this,TabHostActivity.class);//转到我的资料去
					//startActivity(in);
					//overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
					//break;
				case 2:
					in=new Intent(HealthMain.this,Healthedu.class);//转到健康教育去
					startActivity(in);
					overridePendingTransition(R.anim.anim_slide_in_right,R.anim.anim_slide_out_left);
					break;}
			}
		});
	}
	
		@Override
		public void onClick(View v)
		{
		// TODO Auto-generated method stub
		
		}
		
		class MyAdapter extends BaseAdapter {   
		    Activity activity;   
		    private int[] image;    
		    private String[] name;
		    //construct   
		    public MyAdapter(Activity a,int i[],String n[] ) {   
		        activity = a;   
		        this.image=i;
		        this.name=n;
//		        System.out.println("image.length="+image.length);
//		        System.out.println("name.length="+name.length);
		    }   
		       
		    @Override  
		    public int getCount() {   
		        // TODO Auto-generated method stub   
		        return image.length;   
		    }   

		    @Override  
		    public Object getItem(int position) {   
		        // TODO Auto-generated method stub   
		        return image[position];   
		    }   

		    @Override  
		    public long getItemId(int position) {   
		        // TODO Auto-generated method stub   
		        return position;   
		    }   

		    @Override  
		    public View getView(int position, View convertView, ViewGroup parent) {   
		        // TODO Auto-generated method stub   
		    	LinearLayout layout = new LinearLayout(activity);   
		        layout.setOrientation(LinearLayout.VERTICAL);   
		        layout.setGravity(Gravity.CENTER);  
		        ImageView iv = new ImageView(activity);   
		        
		        iv.setImageResource(image[position]);  
		        //iv.setGravity(Gravity.CENTER);
		        
		        layout.addView(iv,new LinearLayout.LayoutParams(70,70));   
		        
//		        System.out.println("position="+position+",name="+name[position]);
		        TextView tv = new TextView(activity); 
		        tv.setWidth(100);
		        tv.setGravity(Gravity.CENTER);   
		        tv.setMaxLines(2);
		        tv.setText(name[position]);
		        tv.setPadding(0, 10, 0, 0);
		        tv.setTextColor(Color.BLACK);
		        tv.setTextSize(16);
		        layout.addView(tv,new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));   
		        
		    	

		        return layout;   
		    } 
		    
		    
		}	
	
}